<?php

namespace Admin\Controller;

use Common\Controller\BaseController;

/**
 * 后台基类
 * 
 * 后台所有（PublicAction除外）的控制器都继承该
 * 在该类中实现登陆验证、权限控制和一些初始化操作
 * 
 * @author: xuhui <xuh86@126.com>
 * @version: $Id$
 * @package: asoc.Admin.Controller
 * 
 */


class CommonController extends BaseController {
	
	protected $pageSize = 20;	//分页参数
	
	function _initialize(){
		
		parent::_initialize();
		
		$adminId	=	session(C('BE_UID'));

		//登陆验证
		if(!$adminId)	$this->redirect("Public/login");
		
		//权限验证
		if(!D('Access')->isAccess())	$this->redirect("Public/noaccess");
		
		//管理员信息
		$adminModel	=	D('Admin');
		$this->assign('admin',$adminModel->getAdminByUid($adminId));
		
		//获取操作菜单
		$sysMenu	=	D('SysMenu');
		$this->assign('menuList',$sysMenu->getMenuList());
		
		//当前操作的模块、操作名称【用于生成面包屑导航】
		$this->assign('actionMeta',$sysMenu->getActionMeta());
		
		//如果是列表也则获取相关的增删改操作名称
		
		if(substr(ACTION_NAME,strlen(ACTION_NAME)-4) == 'List'){
			
			$entity	=	substr(ACTION_NAME,0,strlen(ACTION_NAME)-4);
			
			$this->assign('listAction',ACTION_NAME);
			$this->assign('addAction',$entity.'Add');
			$this->assign('modAction',$entity.'Mod');
			
			$this->assign('delAction',$entity.'Del');
		}
		$charLast	=	substr(ACTION_NAME,strlen(ACTION_NAME)-3);
		if($charLast == 'Add' || $charLast == 'Mod'){
			
			$entity	=	substr(ACTION_NAME,0,strlen(ACTION_NAME)-3);
			$this->assign('saveAction',$entity.'Save');
		}
		
	}
	
	/**
	 * 后台分页函数
	 * @param int $count: 分页记录总数
	 * @param int $pageSize: 每页条数
	 * @param array $params: 分页URL携带参数数组
	 * @param int $rollPage: 分页显示数字页码个数
	 */
	function showPage($count, $pageSize ,$params) {
	
		
		$Page = new \Think\Page($count,$pageSize,$params);
		$Page->rollPage   = 5 ;					
		//$Page->setWrap("<a rel='nofollow' |</a>");
		//$Page->setCurrentWrap("<span id='font26'><a rel='nofollow'|</a></span>");
		
		return $Page->show();
	
	}
	
	
	
	
}

?>